// Copyright(c) 2011 Matthew McMullan, Jorel Lalicki and Mike Heise, Jorel Lalicki and Mike Heise. See copying.txt for details.

#ifndef __agml_mod_h__
#define __agml_mod_h__

// make sure that this file is never included directly
#ifndef __agml_agml_h__
#error "Include AGML from agml.h only. This file is not a valid entry point for the library."
#endif

namespace agml {
	super_inline f32 _mod(f32 a, f32 b) {
		return a-((f32)((i32)(a/b)))*b;
	}

	super_inline void _mod(_v128 a, _v128 b) {
		union { /* you are not   */
			__m128i itmp; /*     */
			_v128 tmp; /*expected*/
		}; /* to understand this */
		tmp = _mm_div_ps ( a , b );
		itmp= _mm_cvtps_epi32(tmp);
		tmp =_mm_cvtepi32_ps(itmp);
		tmp = _mm_mul_ps( tmp, b );
		a   = _mm_sub_ps( a, tmp );
	}
}

#endif
